import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },
  // 工作台 Workbench
  {
    path: '/',
    component: Layout,
    redirect: '/workbench',
    children: [{
      path: 'workbench',
      name: 'Workbench',
      component: () => import('@/views/Workbench'),
      meta: { title: '工作台', icon: 'el-icon-box' }
    }]
  },
  {
    path: '/details',
    component: () => import('@/components/details'),
    redirect: '/details/null',
    children: [
      {
        path: 'null',
        component: () => import('@/views/Workbench')
      }
    ]
  },
  // 基础信息管理 FoundationInfoManage
  {
    path: '/foundationInfoManage',
    component: Layout,
    redirect: '/FoundationInfoManage',
    name: 'foundationInfoManage',
    meta: { title: '基础信息管理', icon: 'el-icon-tickets' },
    children: [
      {
        path: 'warehouseManagement',
        name: 'warehouseManagement',
        meta: { title: '仓库管理', icon: 'el-icon-minus' },
        component: () => import('@/views/FoundationInfoManage/components/WarehouseManagement')
      },
      // 跳转新建信息
      {
        path: 'warehouseManagement/detaill/:id',
        name: 'details',
        component: () => import('@/components/details/null')
      },
      {
        path: 'reservoirAreaManagement',
        name: 'reservoirAreaManagement',
        component: () => import('@/views/FoundationInfoManage/components/ReservoirAreaManagement'),
        meta: { title: '库区管理', icon: 'el-icon-minus' }
      },
      {
        path: 'locationManagement',
        name: 'locationManagement',
        component: () => import('@/views/FoundationInfoManage/components/LocationManagement'),
        meta: { title: '库位管理', icon: 'el-icon-minus' }
      },
      {
        path: 'binLocationView',
        name: 'binLocationView',
        component: () => import('@/views/FoundationInfoManage/components/BinLocationView'),
        meta: { title: '库位视图', icon: 'el-icon-minus' }
      },
      {
        path: 'GoodsManagement',
        name: 'GoodsManagement',
        component: () => import('@/views/FoundationInfoManage/components/GoodsManagement'),
        meta: { title: '货品管理', icon: 'el-icon-minus' }
      },
      {
        path: 'itemTypeManagement',
        name: 'itemTypeManagement',
        component: () => import('@/views/FoundationInfoManage/components/ItemTypeManagement'),
        meta: { title: '货品类型管理', icon: 'el-icon-minus' }
      }
    ]
  },
  // 商务管理 businessManagement
  {
    path: '/businessManagement',
    component: Layout,
    redirect: '/businessManagement',
    name: 'businessManagement',
    meta: { title: '商务管理', icon: 'el-icon-suitcase' },
    children: [
      {
        path: 'carrierManagement',
        name: 'carrierManagement',
        component: () => import('@/views/BusinessManagement/components/CarrierManagement'),
        meta: { title: '货主管理', icon: 'el-icon-minus' }
      },
      {
        path: 'shipperManagement',
        name: 'shipperManagement',
        component: () => import('@/views/BusinessManagement/components/ShipperManagement'),
        meta: { title: '承运商管理', icon: 'el-icon-minus' }
      }
    ]
  },
  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
